import { Component } from '@angular/core';
import { App, Platform } from 'ionic-angular';
import {StatusBar, Splashscreen} from 'ionic-native';
import {AboutPage, SettingsPage, MainPage} from '../pages';

@Component({
  templateUrl: './app.html',
})

export class AppComponent {
  title = 'app';
  public rootPage: AboutPage;

  constructor(private app: App,
             private platform: Platform) {
    platform.ready().then(() => this.onPlatformReady());
  }

  private onPlatformReady() {
    StatusBar.styleDefault();
    Splashscreen.hide();

    // Register hardware back button action for Android and Windows Phone
    this.platform.registerBackButtonAction(() => {
      let nav = this.app.getActiveNav();
      let name = nav.getActive().name;
      if (nav.canGoBack()) {
        nav.pop();
      } else if (name === SettingsPage.name) {
        nav.setRoot(SettingsPage);
      } else if (name === MainPage.name) {
        // exit app if on right screen.... not sure which that'll be yet...
        this.platform.exitApp();
      }
    });
  }
}
